package com.cantierinformatici.mygym;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Adapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ListLayout extends LinearLayout implements
		View.OnClickListener {

	private Adapter list;
	private View.OnClickListener mListener;

	public ListLayout(Context context) {
		super(context);
	}

	public ListLayout(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	@Override
	public void onClick(View v) {
		if (mListener != null)
			mListener.onClick(v);
	}

	public void setList(Adapter list) {
		this.list = list;

		// Popolute list
		if (this.list != null) {
			int i;
			for (i = 0; i < this.list.getCount(); i++) {
				View item = list.getView(i, null, null);
				this.addView(item);
			}
			if (i==0){
				setEmpty();
			}
		}
		

	}

	public void setEmpty(){
		TextView txtEmpty = new TextView(getContext());
		txtEmpty.setText(R.string.list_empty);
		this.addView(txtEmpty);
	}
	public void setmListener(View.OnClickListener mListener) {
		this.mListener = mListener;
	}
	
}
